package com.swak.utils;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 集合操作类,补充
 *
 * @author lifeng
 */
@SuppressWarnings("rawtypes")
public final class CollectionUtils extends org.springframework.util.CollectionUtils {

	public static <T> Collection<T> cast(Iterable<T> iterable) {
		return (Collection<T>) iterable;
	}

	public static boolean isNotEmpty(Collection<?> collection) {
		return !isEmpty(collection);
	}

	public static boolean isEmpty(Collection<?> collection) {
		return collection == null || collection.isEmpty();
	}

	public static boolean isNotEmptyMap(Map map) {
		return !isEmptyMap(map);
	}

	public static boolean isEmptyMap(Map map) {
		return map == null || map.size() == 0;
	}

	public static <T> T first(Collection<T> values) {
		if (isEmpty(values)) {
			return null;
		}
		if (values instanceof List) {
			List<T> list = (List<T>) values;
			return list.get(0);
		} else {
			return values.iterator().next();
		}
	}
}
